#define _CRT_SECURE_NO_WARNINGS 1
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
const int N = 20;
int n, m, ans;
int g[N][N], vis[N][N];
int dx[] = { -1,-1,-1,0,0,1,1,1 };
int dy[] = { -1,0,1,-1,1,-1,0,1 };

void dfs(int x, int y, int sum) {
	if (y == m + 1) {
		x++;
		y = 1;
	}
	if (x == n + 1) {
		ans = max(ans, sum);
		return;
	} 
	dfs(x, y + 1, sum);
	int f = 0;
	for (int i = 0; i < 8; i++) {
		int nx = x + dx[i], ny = y + dy[i];
		if (vis[nx][ny]) {
			f = 1;
			break;
		}
	}
	if (!f) {
		vis[x][y] = 1;
		dfs(x, y + 1, sum + g[x][y]);
		vis[x][y] = 0;
	}
}

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int t; cin >> t;
	while (t--) {
		cin >> n >> m;
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= m; j++) {
				cin >> g[i][j];
			}
		}
		memset(vis, 0, sizeof vis);
		ans = 0;
		dfs(1, 1, 0);
		cout << ans << endl;
	}
	return 0;
}